<template>
  <div>
    <div class="line-box">
      <div class="line-top">
        <p class="title">未来三十天游客趋势图</p>
        <p class="bg"></p>
      </div>
      <div class="line-bottom" ref="lineChart"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
// 引入echarts
import 'echarts-liquidfill'
import * as echarts from 'echarts'
// 生命周期函数
onMounted(() => {
  createLineChart()
})
// Dom获取实例对象
let lineChart = ref()
// 函数
const createLineChart = () => {
  const data = [
    ['06-05', 116],
    ['06-06', 129],
    ['06-07', 135],
    ['06-08', 86],
    ['06-09', 73],
    ['06-10', 85],
    ['06-11', 73],
    ['06-12', 68],
    ['06-13', 92],
    ['06-14', 130],
    ['06-15', 245],
    ['06-16', 139],
    ['06-17', 115],
    ['06-18', 111],
    ['06-19', 309],
    ['06-20', 206],
    ['06-21', 137],
    ['06-22', 128],
    ['06-23', 85],
    ['06-24', 94],
    ['06-25', 71],
    ['06-26', 106],
    ['06-27', 84],
    ['06-28', 93],
    ['06-29', 85],
    ['06-30', 73],
    ['07-01', 83],
    ['07-02', 125],
    ['07-03', 107],
    ['07-04', 82],
    ['07-05', 44],
    ['07-06', 72],
    ['07-07', 106],
    ['07-08', 107],
    ['07-09', 66],
    ['07-10', 91],
    ['07-11', 400],
    ['07-12', 113],
    ['07-13', 107],
    ['07-14', 131],
    ['07-15', 111],
    ['07-16', 64],
    ['07-17', 69],
    ['07-18', 88],
    ['07-19', 77],
    ['07-20', 83],
    ['07-21', 111],
    ['07-22', 57],
    ['07-23', 55],
    ['07-24', 60],
  ]
  const dateList = data.map(function (item) {
    return item[0]
  })
  const valueList = data.map(function (item) {
    return item[1]
  })
  const option = {
    tooltip: {
      trigger: 'axis',
    },
    xAxis: {
      data: dateList,
      axisLine: {
        lineStyle: {
          color: '#fff',
        },
      },
      boundaryGap: false,
    },

    yAxis: {
      name: '访问量',
      axisLine: {
        lineStyle: {
          color: '#fff',
        },
      },
      nameTextStyle: {
        align: 'right',
      },
      splitLine: {
        //网格线
        show: false,
      },
    },

    grid: [
      {
        top: '35%',
        bottom: '10%',
      },
    ],
    series: [
      {
        type: 'line',
        showSymbol: false,
        data: valueList,
        areaStyle: {},
        smooth: true,
      },
    ],
  }
  const myChart = echarts.init(lineChart.value, null, { renderer: 'svg' })
  myChart.setOption(option)
  return myChart
}
</script>

<style scoped lang="scss">
.line-box {
  width: 100%;
  height: 92.5%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  .line-top {
    .title {
      color: #59b4e6;
      font-size: 20px;
    }

    .bg {
      width: 68px;
      height: 7px;
      background: url(../../images/dataScreen-title.png);
      margin-top: 20px;
    }
  }
  .line-bottom {
    width: 100%;
    height: 200px;
  }
}
</style>
